package cn.hls.web.controller.dict;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.hls.entity.CarCategory;
import cn.hls.entity.CertSet;
import cn.hls.entity.vo.Msg;
import cn.hls.entity.vo.PageInfo;
import cn.hls.service.CertSetService;
import cn.hls.web.controller.base.BaseController;

/**
 *@fileName: CarCategoryController.java
 *@package: cn.christ.web.controller.biz
 *@Description:  证书到期提醒Controller
 *@author: yinghui.zhang
 *@email: uuhui@163.com
 *@date: 2016-09-25
 */
@Controller
@RequestMapping("/certSet")
public class CertSetController extends BaseController<CarCategory> {
	@Resource(name = "certSetService")
	private CertSetService service;

	/**s
	 * 页面跳转
	 * 
	 * @return ModelAndView
	 * @throws Exception
	 */
	@RequestMapping("/view")
	public ModelAndView view() throws Exception {
		return new ModelAndView("dict/certSet");
	}

	/**
	 * 新增操作
	 * 
	 * @param entity
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/add")
	@ResponseBody
	public Msg add(CertSet entity) throws Exception {
		if (service.exists( entity)) {
			msg.setInfo("证书名称或证书代码已经存在");
			msg.setStatus(201);
		} else {
			boolean flag = service.add(entity);
			if (flag) {
				msg.setInfo("操作成功");
				msg.setStatus(200);
			} else {
				msg.setInfo("操作失败");
				msg.setStatus(200);
			}
		}
		return msg;
	}

	/** 删除操作 **/
	@RequestMapping("/del")
	@ResponseBody
	public Msg del(Long id) throws Exception {
		try {
			service.delete(id);
			msg.setInfo("删除成功");
			msg.setStatus(200);
			return msg;
		} catch (Exception ex) {
			throw ex;
		}
	}

	/**
	 * 分页查询
	 * 
	 * @param page  分页对象
	 * @param entity  查询实时对象
	 * @return PageInfo<payTeam>
	 * @throws Exception
	 */
	@RequestMapping("/list")
	@ResponseBody
	public PageInfo<CertSet> list(PageInfo<CertSet> page, CertSet entity)
			throws Exception {
		return service.loadCertSetInfo(page, entity);
	}

	/**
	 * 更新操作
	 * 
	 * @param entity
	 *           车辆类型对象
	 * @return Msg
	 * @throws Exception
	 */
	@RequestMapping("/update")
	@ResponseBody
	public Msg update(CertSet entity) throws Exception {
		boolean flag = service.update(entity);
		if (flag) {
			msg.setInfo("操作成功");
			msg.setStatus(200);
		} else {
			msg.setInfo("操作失败");
			msg.setStatus(200);
		}
		return msg;
	}
	
}
